﻿/* Windows 扩展类
 */

/*待测试*/
namespace LSLib.Windows
{
    using System;
    using System.Drawing;

    public class WindowsEx
    {
        /// <summary>查找指定位置的窗口句柄
        /// </summary>
        /// <param name="p">p点</param>
        public static IntPtr FindWindowAt(Point p)
        {
            return FindWindowAt(p.X, p.Y);
        }

        /// <summary>查找指定位置的窗口句柄
        /// </summary>
        /// <param name="x">x轴坐标</param>
        /// <param name="y">y轴坐标</param>
        public static IntPtr FindWindowAt(int x, int y)
        {
            return API.Window.WindowFromPoint(x, y);
        }

        /// <summary>查找指定位置的子窗口句柄
        /// </summary>
        /// <param name="hWndParent">父窗口句柄</param>
        /// <param name="x2Parent">相对于父窗口的x轴坐标</param>
        /// <param name="y2Parent">相对于父窗口的y轴坐标</param>
        /// <returns>如果指定位置不存在子窗口，返回IntPtr.Zero，否则返回子窗口句柄</returns>
        public static IntPtr FindChildWindowAt(IntPtr hWndParent, int x2Parent, int y2Parent)
        {
            return FindChildWindowAt(hWndParent, new Point(x2Parent, y2Parent));
        }
        /// <summary>查找指定位置的子窗口句柄
        /// </summary>
        /// <param name="hWndParent">父窗口句柄</param>
        /// <param name="point">相对于父窗口的坐标</param>
        /// <returns>如果指定位置不存在子窗口，返回IntPtr.Zero，否则返回子窗口句柄</returns>
        public static IntPtr FindChildWindowAt(IntPtr hWndParent, Point point)
        {
            IntPtr hWndChild = API.Window.ChildWindowFromPoint(hWndParent, point);
            if (hWndChild == hWndParent) return IntPtr.Zero;
            return hWndChild;
        }
    }
}
